package edu.tgc.service.student;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import org.abyss.common.service.CommonCrudService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.tgc.entity.student.TbClass;
import edu.tgc.entity.system.SysDept;
import edu.tgc.repository.student.TbClassRepository;
@Service
public class TbClassService extends CommonCrudService<TbClass, UUID> {
	
	@Autowired
	private TbClassRepository classDAO;
	
	public List<HashMap<String, Object>> banjiCombo() {
		List<HashMap<String, Object>> result=new ArrayList<>();
		List<TbClass> list=classDAO.findDistinctParentdeptByIsUsedOrderByParentdeptSort(true);
		for (TbClass tbClass : list) {
			SysDept dept=tbClass.getParentdept();
			HashMap<String, Object> node=new HashMap<>();
			node.put("id", dept.getId());
			node.put("text", dept.getName());
			List<TbClass> bjs=classDAO.findByParentdeptAndIsUsed(dept,true);
			List<HashMap<String, Object>> children=new ArrayList<>();
			for (TbClass bj : bjs) {
				HashMap<String, Object> node1=new HashMap<>();
				node1.put("id", bj.getId());
				node1.put("text", bj.getName());
				children.add(node1);
			}
			node.put("children", children);
			node.put("state", "closed");
			result.add(node);
		}
		return result;
	}

	public String getClassNames() {
		List<TbClass> bjs = classDAO.findByIsUsed(true);
		String str="可用的班级名为：\r\n";
		for (TbClass bj : bjs) {
			str+=bj.getName().trim()+"\r\n";
		}
		return str;
	}

}
